#!/bin/bash

usage() {
    app=$(basename $0)
    cat <<EOF
Usage: ./$app [release|testing] <version>
Example:
    ./$app testing 0.3.9
EOF
}

if [[ $# -lt 2 ]]; then
    usage
    exit 1
fi

case $1 in
    'release' | 'testing');;
    *)
        usage
        exit 1
        ;;
esac

if [[ $(uname) == 'Darwin' ]]; then
    sedi='sed -i ""'
else
    sedi='sed -i'
fi

DIR=$PWD/$1/$2
mkdir -p $DIR
PLIST=$DIR/jzf.plist
cat >$PLIST<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>items</key>
	<array>
		<dict>
			<key>assets</key>
			<array>
				<dict>
					<key>kind</key>
					<string>software-package</string>
					<key>url</key>
					<string>https://git.oschina.net/fzhcl/ipa/raw/master/$1/$2/jzf.ipa</string>
				</dict>
			</array>
			<key>metadata</key>
			<dict>
				<key>bundle-identifier</key>
				<string>com.jizhenfang.jizhen</string>
				<key>bundle-version</key>
				<string>$2</string>
				<key>kind</key>
				<string>software</string>
				<key>title</key>
				<string>集珍坊</string>
			</dict>
		</dict>
	</array>
</dict>
</plist>
EOF
